package com.ocom.webapi.controller;

import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.entity.card.EntityXfMealTime;
import com.ocom.common.request.web.ConsTimeConfigOnShowRequest;
import com.ocom.common.resp.Result;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.PayConfigClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 身份消费时区
 * @Author: 朱晖
 * @Date: 2023/7/12
 **/
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class ConsTimeConfigController {

	@Autowired
	private PayConfigClientService payConfigClientService;

	@PostMapping(WebApiServiceUrl.Url_ConsTimeConfigOnShow)
	public Result OnShow(@Valid @RequestBody ConsTimeConfigOnShowRequest request){
		request.setPage(-1);
		request.setSize(-1);
		request.setComId(SecurityUtils.getYoCiUser().getComId());
		return payConfigClientService.GetMealTimeInfo(request);
	}

	@PostMapping(WebApiServiceUrl.Url_ConsTimeConfigAdd)
	public Result Add(@RequestBody EntityXfMealTime entityXfMealTime){
		entityXfMealTime.setComId(SecurityUtils.getYoCiUser().getComId());
		return payConfigClientService.AddMealTimeInfo(entityXfMealTime);
	}

	@PostMapping(WebApiServiceUrl.Url_ConsTimeConfigModify)
	public Result Modify(@RequestBody EntityXfMealTime entityXfMealTime){
		entityXfMealTime.setComId(SecurityUtils.getYoCiUser().getComId());
		return payConfigClientService.UpdateMealTimeInfo(entityXfMealTime);
	}


	@PostMapping(WebApiServiceUrl.Url_ConsTimeConfigRemove)
	public Result Remove(@Valid @RequestBody EntityXfMealTime entityXfMealTime){
		Map<String, Object> map = new HashMap<>();
		map.put("comId",SecurityUtils.getYoCiUser().getComId());
//		map.put("mealNo",entityXfMealTime.getMealNo());
		map.put("id",entityXfMealTime.getId());
		return payConfigClientService.DeleteMealTimeInfo(map);
	}


}
